using System;
namespace MicroMsg.UI.Util
{
	internal class LunarDay
	{
		private static string[] TianGan = new string[]
		{
			"甲",
			"乙",
			"丙",
			"丁",
			"戊",
			"己",
			"庚",
			"辛",
			"壬",
			"癸"
		};
		private static string[] DiZhi = new string[]
		{
			"子",
			"丑",
			"寅",
			"卯",
			"辰",
			"巳",
			"午",
			"未",
			"申",
			"酉",
			"戌",
			"亥"
		};
		private static string[] ShengXiao = new string[]
		{
			"鼠",
			"牛",
			"虎",
			"兔",
			"龙",
			"蛇",
			"马",
			"羊",
			"猴",
			"鸡",
			"狗",
			"猪"
		};
		private static string[] DayName = new string[]
		{
			"*",
			"初一",
			"初二",
			"初三",
			"初四",
			"初五",
			"初六",
			"初七",
			"初八",
			"初九",
			"初十",
			"十一",
			"十二",
			"十三",
			"十四",
			"十五",
			"十六",
			"十七",
			"十八",
			"十九",
			"二十",
			"廿一",
			"廿二",
			"廿三",
			"廿四",
			"廿五",
			"廿六",
			"廿七",
			"廿八",
			"廿九",
			"三十"
		};
		private static string[] MonthName = new string[]
		{
			"*",
			"正",
			"二",
			"三",
			"四",
			"五",
			"六",
			"七",
			"八",
			"九",
			"十",
			"十一",
			"腊"
		};
		private static int[] MonthAdd = new int[]
		{
			0,
			31,
			59,
			90,
			120,
			151,
			181,
			212,
			243,
			273,
			304,
			334
		};
		private static int[] LunarData = new int[]
		{
			2635,
			333387,
			1701,
			1748,
			267701,
			694,
			2391,
			133423,
			1175,
			396438,
			3402,
			3749,
			331177,
			1453,
			694,
			201326,
			2350,
			465197,
			3221,
			3402,
			400202,
			2901,
			1386,
			267611,
			605,
			2349,
			137515,
			2709,
			464533,
			1738,
			2901,
			330421,
			1242,
			2651,
			199255,
			1323,
			529706,
			3733,
			1706,
			398762,
			2741,
			1206,
			267438,
			2647,
			1318,
			204070,
			3477,
			461653,
			1386,
			2413,
			330077,
			1197,
			2637,
			268877,
			3365,
			531109,
			2900,
			2922,
			398042,
			2395,
			1179,
			267415,
			2635,
			661067,
			1701,
			1748,
			398772,
			2742,
			2391,
			330031,
			1175,
			1611,
			200010,
			3749,
			527717,
			1452,
			2742,
			332397,
			2350,
			3222,
			268949,
			3402,
			3493,
			133973,
			1386,
			464219,
			605,
			2349,
			334123,
			2709,
			2890,
			267946,
			2773,
			592565,
			1210,
			2651,
			395863,
			1323,
			2707,
			265877
		};
		public static string GetLunarCalendar(DateTime dtDay)
		{
			string text = dtDay.get_Year().ToString();
			string text2 = dtDay.get_Month().ToString();
			string text3 = dtDay.get_Day().ToString();
			int num;
			int num2;
			int num3;
			try
			{
				num = int.Parse(text);
				num2 = int.Parse(text2);
				num3 = int.Parse(text3);
			}
			catch
			{
				num = DateTime.get_Now().get_Year();
				num2 = DateTime.get_Now().get_Month();
				num3 = DateTime.get_Now().get_Day();
			}
			string text4 = string.Empty;
			int num4 = (num - 1921) * 365 + (num - 1921) / 4 + num3 + LunarDay.MonthAdd[num2 - 1] - 38;
			if (num % 4 == 0 && num2 > 2)
			{
				num4++;
			}
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			int i = 0;
			IL_148:
			while (num5 != 1)
			{
				if (LunarDay.LunarData[num6] < 4095)
				{
					num7 = 11;
				}
				else
				{
					num7 = 12;
				}
				i = num7;
				while (i >= 0)
				{
					int num8 = LunarDay.LunarData[num6];
					for (int j = 1; j < i + 1; j++)
					{
						num8 /= 2;
					}
					num8 %= 2;
					if (num4 > 29 + num8)
					{
						num4 = num4 - 29 - num8;
						i--;
					}
					else
					{
						num5 = 1;
						IL_13D:
						if (num5 != 1)
						{
							num6++;
							goto IL_148;
						}
						goto IL_14D;
					}
				}
				goto IL_13D;
			}
			IL_14D:
			num = 1921 + num6;
			num2 = num7 - i + 1;
			num3 = num4;
			if (num7 == 12)
			{
				if (num2 == LunarDay.LunarData[num6] / 65536 + 1)
				{
					num2 = 1 - num2;
				}
				else
				{
					if (num2 > LunarDay.LunarData[num6] / 65536 + 1)
					{
						num2--;
					}
				}
			}
			text4 = num + "年";
			text4 = text4 + LunarDay.ShengXiao[(num - 4) % 60 % 12].ToString() + "年 ";
			text4 += LunarDay.TianGan[(num - 4) % 60 % 10].ToString();
			text4 = text4 + LunarDay.DiZhi[(num - 4) % 60 % 12].ToString() + " ";
			if (num2 < 1)
			{
				text4 = text4 + "闰" + LunarDay.MonthName[-1 * num2].ToString() + "月";
			}
			else
			{
				text4 = text4 + LunarDay.MonthName[num2].ToString() + "月";
			}
			return text4 + LunarDay.DayName[num3].ToString() + "日";
		}
		public static int GetLunarCalendarDay(DateTime dtDay)
		{
			int num = dtDay.get_Year();
			int num2 = dtDay.get_Month();
			int day = dtDay.get_Day();
			int num3 = (num - 1921) * 365 + (num - 1921) / 4 + day + LunarDay.MonthAdd[num2 - 1] - 38;
			if (num % 4 == 0 && num2 > 2)
			{
				num3++;
			}
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			int i = 0;
			IL_CD:
			while (num4 != 1)
			{
				if (LunarDay.LunarData[num5] < 4095)
				{
					num6 = 11;
				}
				else
				{
					num6 = 12;
				}
				i = num6;
				while (i >= 0)
				{
					int num7 = LunarDay.LunarData[num5];
					for (int j = 1; j < i + 1; j++)
					{
						num7 /= 2;
					}
					num7 %= 2;
					if (num3 > 29 + num7)
					{
						num3 = num3 - 29 - num7;
						i--;
					}
					else
					{
						num4 = 1;
						IL_C2:
						if (num4 != 1)
						{
							num5++;
							goto IL_CD;
						}
						goto IL_D2;
					}
				}
				goto IL_C2;
			}
			IL_D2:
			num = 1921 + num5;
			num2 = num6 - i + 1;
			return num3;
		}
	}
}
